import { ISDK } from "../ISDK";

export class WXSDK {
    Login():Promise<any>{
        console.log("WxLogin");
        return new Promise<any>((resolve, reject) => {
            wx.login({
                success: function (res) {
                    resolve(res.code);
                },
                fail: function(res){
                    reject(res.errMsg);
                }
            });
        });
    }
    
    GetUserInfo():Promise<any>{
        return new Promise<any>((resolve, reject) => {
            wx.getUserInfo({
                success: function (res) {
                    resolve(res.userInfo);
                },
                fail: function(res){
                    reject(res.errMsg);
                }
            });
        });
    }

    GetUserImage(url:string, sprite: cc.Sprite): void {
        let image = wx.createImage();
        image.onload = function () {
            let texture = new cc.Texture2D();
            texture.initWithElement(image);
            texture.handleLoadedTexture();
            sprite.spriteFrame = new cc.SpriteFrame(texture);
        };
        image.src = url;
    }
}



